/*
 * Copyright (C) 2009  Sylvain Maucourt (smaucourt@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *
 */
package net.sylvek.where;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceChangeListener;

public class Settings extends PreferenceActivity {

    private SharedPreferences pref;

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
        pref = PreferenceManager.getDefaultSharedPreferences(this);

        /* if private we disallow auto update */
        final boolean isPrivate = pref.getBoolean("net.sylvek.where.private", false);
        final Preference serviceLocation = findPreference("net.sylvek.where.service.update_location");
        final Preference serviceLocationDistance = findPreference("net.sylvek.where.service.distance");
        final Preference serviceLocationTime = findPreference("net.sylvek.where.service.time");
        serviceLocation.setEnabled(!isPrivate);
        findPreference("net.sylvek.where.private").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue)
            {
                serviceLocation.setEnabled(!(Boolean) newValue);
                serviceLocationDistance.setEnabled(!(Boolean) newValue);
                serviceLocationTime.setEnabled(!(Boolean) newValue);
                return true;
            }
        });
    }
}
